/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ttt.nor2.thread;

import com.ttt.nor2.alarm.ALarmSendSMS;
import com.ttt.nor2.config.CfgAlarm;
import com.ttt.nor2.db.ALarmFromExchange;
import org.apache.log4j.Logger;

/**
 *
 * @author anuphabm
 */
public class ThManageAlarm extends Thread {
    private Logger logger = Logger.getLogger(ThManageAlarm.class);
    private ALarmFromExchange alarm;
    private static int thWork = 0;
    private CfgAlarm cfg;



    public static int getThWork() {
        return thWork;
    }

    static synchronized void incThread() {
        thWork++;
    }

    synchronized void decThread() {
        thWork--;
    }

    public ThManageAlarm(CfgAlarm cfg, ALarmFromExchange alarm) {
        this.cfg = cfg;
        this.alarm = alarm;
        incThread();
        logger.debug("work thread " + thWork);

    }

    @Override
    public void run() {
        ALarmSendSMS send = new ALarmSendSMS(alarm, cfg);
        send.prcess();
        decThread();
        logger.debug("work thread " + thWork);
    }
}
